import { SimpleEntity } from "./common";
import store from '@store';
import { User } from "./user";

/**
 * websocket 协议的请求
 */
export class WebSocketRequest<T> {

    /** 接收方 */
    receiver    : SimpleEntity;

    /** 发送方 */
    sender      : SimpleEntity;

    /** 数据 */
    data        : T;

    /**
     * @param receiver 接收方
     * @param data 数据
     */
    constructor(receiver: User | SimpleEntity, data: T) {
        console.log(receiver)
        let me: User = store.getters.me();
        this.sender = new SimpleEntity(me.id, me.name);
        this.receiver = new SimpleEntity(receiver.id, receiver.name);
        this.data = data;
    }

}

/**
 * websocket 协议的响应, 需要指明响应类型, 由哪个方法处理, 响应数据以及附带消息
 */
export class WebSocketResponse {

    /** 响应类型 */
    type    : WebSocketResponseType = WebSocketResponseType.TIP;

    /** 处理方法名 */
    handler : string;

    /** 响应数据 */
    data    : string;

    /** 附带消息 */
    msg     : string;

}

/**
 * websocket 响应类型
 */
export enum WebSocketResponseType {

    /** 仅提示 */
    TIP = "TIP",

    /** 系统消息 */
    SYSTEM = "SYSTEM",

    /** 私信 */
    PRIVATE = "PRIVATE"

}